package com.sskj.cndragon.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.cndragon.http.HttpConfig;
import com.sskj.cndragon.ui.activity.ChangePwdActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.http.JsonCallBack;


public class ChangePwdActivityPresenter extends BasePresenter<ChangePwdActivity> {
    public void getCode(String tel, int codeType) {
        httpService.getCode(tel, codeType)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == BaseHttpConfig.OK) {
                            mView.getCodeSuccess();
                        }
                    }
                });
    }

    public void changeLoginPwd(String mobile, String mobileCode, String pwd) {
        httpService.findPwd(mobile, mobileCode, MD5Util.getMd5Value(pwd))
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == BaseHttpConfig.OK) {
                            mView.changeLoginPwdSuccess();
                        }
                    }
                });
    }

    public void changePayPwd(String mobile, String mobileCode, String pwd) {
        httpService.payPwd(mobile, mobileCode, MD5Util.getMd5Value(pwd))
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.changPayPwdSuccess();
                        }
                    }
                });
    }

}
